package Servlet.User;

import Service.BorrowService;
import Table.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/userBorrowServlet")
public class UserBorrowServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取书的id
        String id = req.getParameter("id");
        int i = Integer.parseInt(id);
        //获取用户的id
        User user = (User) req.getSession().getAttribute("user");
        Boolean flag = BorrowService.Borrow(i, user.getId());
        PrintWriter out = resp.getWriter();
        out.print(flag);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
